package com.terabits.smartriver.controller;

import com.terabits.smartriver.constants.result.BaseResp;
import com.terabits.smartriver.constants.result.ResultStatus;
import com.terabits.smartriver.meta.po.Enterprise;
import com.terabits.smartriver.service.EnterpriseService;
import com.terabits.smartriver.util.PageData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业管理接口
 */
@CrossOrigin
@RestController
public class EnterpriseController extends BaseController {
    @Autowired
    private EnterpriseService enterpriseService;

    @CrossOrigin
    @ApiOperation(value = "查询 企业", tags = {"企业管理"})
    @RequestMapping(value = "/enterprise-mgt/enterprise/get", method = RequestMethod.GET)
    public BaseResp getEnterprise() {
        List<PageData> enterprises = enterpriseService.getEnterprise(this.getPageData());
        return new BaseResp(ResultStatus.SUCCESS, enterprises);
    }

    @ApiOperation(value = "添加 企业", tags = {"企业管理"})

    @RequestMapping(value = "/enterprise-mgt/enterprise/add", method = RequestMethod.POST)
    public BaseResp addEnterprise(Enterprise enterprise) {
        int addRes = enterpriseService.addEnterprise(enterprise);
        if (addRes==-1){
            return new BaseResp(ResultStatus.error_duplicated_data);
        }
        return new BaseResp(ResultStatus.SUCCESS, addRes);
    }

    @ApiOperation(value = "修改 企业", tags = {"企业管理"})
    @RequestMapping(value = "/enterprise-mgt/enterprise/update", method = RequestMethod.POST)
    public BaseResp updateEnterprise(Enterprise enterprise) {
        return new BaseResp(ResultStatus.SUCCESS, enterpriseService.updateEnterprise(enterprise));
    }

    @ApiOperation(value = "删除 企业", tags = {"企业管理"})
    @RequestMapping(value = "/enterprise-mgt/enterprise/delete", method = RequestMethod.POST)
    public BaseResp deleteEnterprise(Integer id) {
        int res = enterpriseService.deleteEnterprise(id);
        if (res == -1) {
            return new BaseResp(ResultStatus.error_delete_failed);
        }
        return new BaseResp(ResultStatus.SUCCESS, res);
    }
}
